/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package sisgraf.controler;
import sisgraf.dao.CorDaoImp;
import sisgraf.model.Cor;
import java.util.List;
import javax.swing.table.TableModel;
import javax.swing.JTable;
/**
 *
 * @author jordan
 */
public class CorControler extends Controler {
    private CorDaoImp daoLock = new CorDaoImp();
    public TableModel getListarCor() {
        List<Cor> lista = new CorDaoImp().list("");
        String[] cabecalho = new String[]  {"Cod.","Descricao"};
        TableModel modelo = new CorTabela(lista, cabecalho);
        return modelo;
    }
    public void ajustarTabela(JTable tabela){
        int[] tamCol = new int[] {2,10};
        super.ajustarTabela(tabela, tamCol);
    }

    public Cor prepararAlterarCor(int id){
        return daoLock.getLockCor(id);
    }
    public Cor leCor(int id){
        return daoLock.getCor(id);
    }
    public boolean excluirCor(Cor cor) {
        CorDaoImp dao = new CorDaoImp();
        return dao.remove(cor);
    }
    public boolean adicionarCor(Cor cor){
        CorDaoImp dao = new CorDaoImp();
        return dao.save(cor);
    }

    public boolean alterarCor(Cor cor){
        if (!daoLock.settLockCor(cor)){
            return false;
        } else {
            return true;
        }
    }
    public boolean liberarCor(){
        if (!daoLock.unLockCor()){
            return false;
        } else {
            return true;
        }
    }
}
